#include"namedPipe.hpp"

// server read: 管理命名管道的整个生命周期
int main()
{
    NamePiped fifo(comm_path,Creater);
    //对于读端而言，如果我们打开了但没有写入，我们会阻塞在open调用中，指导写入
    //进程同步
    if(fifo.OpenForRead())
    {
         std::cout << "server open named pipe done" << std::endl;
         sleep(3);
         while(true)
         {
            std::string message;
            int n=fifo.ReadNamePipe(&message);
            if (n > 0)
            {
                std::cout << "Client Say> " << message << std::endl;
            }
            else if(n == 0)
            {
                std::cout << "Client quit, Server Too!" << std::endl;
                break;
            }
            else
            {
                std::cout << "fifo.ReadNamedPipe Error" << std::endl;
                break;
            }
         }
    }
}